home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 7
/
Apprentice-Release7.iso
/
Source Code
/
Pascal
/
Applications
/
DropBin 1.5
/
DropBinUtils.p
< prev
next >
Wrap
Text File
|
1997-04-16
|
4KB
|
202 lines
Unit DropBinUtils;
Interface
Uses
Toolbox;
Const
kAppleNum = 128;
kFileNum = 129;
kAlertID = 200;
kMessageID = 201;
kReturnkey = 13;
kEnterKey = 3;
kEscapeKey = 27;
kShowRemaining = 0;
kShowProcessed = 1;
kShowTotal = 2;
Var
gBackGround,
gHasAppleEvents,
gWasEvent: boolean;
gEvent: EventRecord;
gDone: boolean;
gOApped: boolean; { opened application versus dropping document onto app }
gState: boolean; { determines when it's times to setup progress bar stuff }
gProcessing: boolean; { binhex in progress }
gFilename: str255;
gOutputName: str255;
gStatType: integer;
gRefNum: integer;
gAppleMenu, gFileMenu: MenuHandle;
mainCRC: unsignedLong;
dbWindow: DialogPtr;
encodeButton: ControlHandle;
quitButton: ControlHandle;
cancelButton: ControlHandle;
Procedure DisplayMsg(name: Str255);
Procedure AlertUser(name: Str255; err: integer);
Function AddPtrLong (p: univ Ptr; offset: longint): Ptr;
Procedure OffsetPtr (var p: univ Ptr; offset: longint);
Procedure PtrUpdate(p: Ptr; offset: longint; bytevalue: univ SignedByte);
Function MaxValue(num1, num2: longint): longint;
Function DBFormat(num: longint): str255;
Procedure StringToRect(str: str255; r: rect; size: integer; face: style);
Procedure AppendToRect(str: str255);
Procedure CenterAlert(theID: integer);
Procedure ErrorAlert(stringListID, stringIndexID, errorID: integer);
Implementation
{$NR+}
Procedure DisplayMsg(name: Str255);
begin
ParamText(name,'','','');
Alert(kMessageID,nil);
end;
Procedure AlertUser(name: Str255; err: integer);
Var
str: str255;
begin
if err = 0 then
str := ''
else
numToString(err,str);
ParamText(name,str,'','');
err := Alert(kAlertID,nil);
end;
Function AddPtrLong (p: univ Ptr; offset: longint): Ptr;
begin
AddPtrLong := Ptr(ord(p) + offset);
end;
Procedure OffsetPtr (var p: univ Ptr; offset: longint);
begin
p := Ptr(ord(p) + offset);
end;
Procedure PtrUpdate(p: Ptr; offset: longint; bytevalue: univ SignedByte);
begin
BlockMoveData(@bytevalue, Ptr(ord4(p) + offset), 1);
end;
Function MaxValue(num1, num2: longint): longint;
begin
if num1 >= num2 then
MaxValue := num1
else
MaxValue := num2;
end;
Function DBFormat(num: longint): str255;
Var
r: real;
suffix: str3;
str: str255;
begin
r := num;
if r > 1024 then
begin
r := r / 1024;
if r > 1024 then
begin
r := r / 1024;
suffix := 'M';
end
else
suffix := 'K';
NumToString(trunc(r * 10), str);
str := copy(str,1,length(str) - 1) + '.' + str[length(str)] + suffix;
// str := StringOf(r:10:1,suffix);
end
else
NumToString(num, str);
DBFormat := str;
end; { of DBFormat }
Procedure StringToRect(str: str255; r: rect; size: integer; face: style);
Var
theNum: integer;
begin
EraseRect(r);
MoveTo(r.left, r.top + (r.bottom - r.top) div 2);
GetFNum('Geneva', theNum);
TextFont(theNum);
TextSize(size);
TextFace(face);
DrawString(str);
TextFace([]);
TextFont(0);
TextSize(0);
end;
Procedure AppendToRect(str: str255);
Var
theNum: integer;
begin
{ Assumes that we're already where we're supposed to be }
GetFNum('Geneva', theNum);
TextFont(theNum);
TextSize(9);
TextFace([]);
DrawString(str);
TextFont(0);
TextSize(0);
end;
Procedure CenterAlert(theID: integer);
Var
theX, theY: integer;
theAlertHandle: AlertTHndl;
screen, alrt: rect;
begin
theAlertHandle := AlertTHndl(GetResource('ALRT',theID));
if theAlertHandle <> NIL then
begin
HLock(Handle(theAlertHandle));
alrt := theAlertHandle^^.boundsRect;
screen := qd.screenBits.bounds;
theX := BSR(((screen.right - screen.left ) - (alrt.right - alrt.left )),1);
theY := BSR((( screen.bottom - screen.top ) + GetMBarHeight - (alrt.bottom - alrt.top)),1);
theY := theY - BSR(( screen.bottom - screen.top ),2); { this moves it up for better viewing! }
OffsetRect(theAlertHandle^^.boundsRect, theX - alrt.left, theY - alrt.top);
end;
SetCursor(qd.arrow);
end;
Procedure ErrorAlert(stringListID, stringIndexID, errorID: integer);
Var
param,errorStr: Str255;
begin
if errorID = noErr then
exit(ErrorAlert);
NumToString(errorID, errorStr);
GetIndString(param, stringListID, stringIndexID);
ParamText(param, errorStr, '', '');
CenterAlert(kAlertID);
Alert(kAlertID, NIL);
end;
End.